import pygame
image1=pygame.image.load("longfur_stand.bmp")
image1.set_colorkey((255,0,255))
image2=pygame.image.load("human_2.jpg")
image3=pygame.image.load("longfur_crawl.bmp")
image3.set_colorkey((255,0,255))
image4=pygame.image.load("human_4.jpg")

import DECISIONS
import Something

FREE_FALL_START=0
FREE_FALL=1
ON_GROUND=2
CRAWL=3
ON_GROUND_WALKING=4
ON_GROUND_BY_WALL=5
CRAWL_BY_WALL=6
BY_WALL=7
CLING_BY_WALL=8
ON_CEILING_BY_WALL=9
ON_CEILING=10
ON_THIN=11
BY_SLIM=12
ON_GROUND_RUNNING=13
TO_SCUD=14

DRAGS=-1

class Character(Something.Something):
	def figureNextState(self):
		if self.currentState==FREE_FALL_START:
			dx,dy=self.freeFall(Fx=self.Fx,Fy=self.Fy)
			self.dx=self.dx+dx
			self.dy=self.dy+dy
		elif self.currentState==FREE_FALL:
			if self.inStateFor==1:
				self.crawl=False
				self.dragging=None
			if DECISIONS.MOVE_LEFT in self.decisionQueue:
				self.dx=self.dx-0.5
			elif DECISIONS.MOVE_RIGHT in self.decisionQueue:
				self.dx=self.dx+0.5
			dx,dy=self.freeFall(Fx=self.Fx,Fy=self.Fy)
			self.dx=self.dx+dx
			self.dy=self.dy+dy
		elif self.currentState==TO_SCUD:
			if self.inStateFor==7:
				self.currentState=ON_GROUND_RUNNING
				self.inStateFor=0
			elif self.facingRight:
				self.dx=self.dx+self.getScudSpeed()
			else:
				self.dx=self.dx-self.getScudSpeed()
		elif self.currentState==ON_GROUND_RUNNING:
			if not DECISIONS.RUN in self.decisionQueue:
				self.currentState=ON_GROUND_WALKING
				self.inStateFor=0
			elif DECISIONS.MOVE_LEFT in self.decisionQueue:
				self.dx=self.dx-self.getRunningSpeed()
			elif DECISIONS.MOVE_RIGHT in self.decisionQueue:
				self.dx=self.dx+self.getRunningSpeed()
			else:
				self.currentState=ON_GROUND
				self.inStateFor=0
			if self.inStateFor!=0 and DECISIONS.MOVE_DOWN_START in self.decisionQueue:
				self.currentState=TO_SCUD
				self.inStateFor=0
		elif self.currentState==BY_SLIM:
			if DECISIONS.MOVE_UP in self.decisionQueue:
				self.dy=self.dy+9
			elif DECISIONS.MOVE_DOWN in self.decisionQueue:
				self.dy=self.dy-9
			if DECISIONS.MOVE_RIGHT in self.decisionQueue and DECISIONS.JUMP in self.decisionQueue:
				self.facingRight=True
				self.dy=self.dy+9
				self.dx=self.dx+14
				self.x_bound.unbound(self)
			elif DECISIONS.MOVE_RIGHT in self.decisionQueue:
				self.facingRight=True
				if self.x_bound.swingable():
					self.x_bound.moveLowerPoint(+105)
			elif DECISIONS.MOVE_LEFT in self.decisionQueue and DECISIONS.JUMP in self.decisionQueue:
				self.facingRight=False
				self.dy=self.dy+9
				self.dx=self.dx-14
				self.x_bound.unbound(self)
			elif DECISIONS.MOVE_LEFT in self.decisionQueue:
				self.facingRight=False
				if self.x_bound.swingable():
					self.x_bound.moveLowerPoint(-105)
		elif self.currentState==DRAGS:
			if not (-1.2*0.5*(self.getWidth()+self.dragging.getWidth())<=self.x-self.dragging.x<=1.2*0.5*(self.getWidth()+self.dragging.getWidth())) or DECISIONS.DRAG_START in self.decisionQueue:
				self.dragging=None
				self.currentState=ON_GROUND
				self.inStateFor=0
			else:
				if self.x<self.dragging.x and self.x-self.dragging.x!=-0.5*(self.getWidth()+self.dragging.getWidth()):
					self.x=self.dragging.x-0.5*(self.getWidth()+self.dragging.getWidth())
				elif self.x>self.dragging.x and self.x-self.dragging.x!=0.5*(self.getWidth()+self.dragging.getWidth()):
					self.x=self.dragging.x+0.5*(self.getWidth()+self.dragging.getWidth())
				print "q"
			if self.dragging:
				if DECISIONS.MOVE_LEFT in self.decisionQueue and not (self.dragging.x_bound and not self.dragging.facingRight):
					#self.facingRight=False
					self.dx=self.dx-self.getWalkingSpeed()
					self.dragging.dx=self.dragging.dx-self.getWalkingSpeed()
				elif DECISIONS.MOVE_RIGHT in self.decisionQueue and not (self.dragging.x_bound and self.dragging.facingRight):
					#self.facingRight=True
					self.dx=self.dx+self.getWalkingSpeed()
					self.dragging.dx=self.dragging.dx+self.getWalkingSpeed()
		elif self.currentState==CLING_BY_WALL:
			print "cling situation"
			#print self.x_bound.pos
			if self.x_bound.x_cross and DECISIONS.MOVE_LEFT in self.decisionQueue and DECISIONS.JUMP in self.decisionQueue and not self.facingRight:
				self.x_bound.to_x_other_side(self)
			elif self.x_bound.x_cross and DECISIONS.MOVE_RIGHT in self.decisionQueue and DECISIONS.JUMP in self.decisionQueue and self.facingRight:
				self.x_bound.to_x_other_side(self)
			elif DECISIONS.MOVE_UP in self.decisionQueue or (DECISIONS.MOVE_LEFT in self.decisionQueue and not self.facingRight) or (DECISIONS.MOVE_RIGHT in self.decisionQueue and self.facingRight):
				self.dy=self.dy+7
			elif DECISIONS.MOVE_DOWN in self.decisionQueue and self.y+self.getHeight()>self.x_bound.upperSide():
				#if self.y+self.getHeight()-self.x_bound.upperSide()<7:
				d=self.y+self.getHeight()-self.x_bound.upperSide() if self.y+self.getHeight()-self.x_bound.upperSide()<7 else 7
				self.dy=self.dy-d
			elif DECISIONS.MOVE_LEFT in self.decisionQueue and DECISIONS.JUMP in self.decisionQueue and self.facingRight:
				self.facingRight=False
				self.dy=self.dy+9
				self.dx=self.dx-14
				self.x_bound.unbound(self)
			elif DECISIONS.MOVE_RIGHT in self.decisionQueue and DECISIONS.JUMP in self.decisionQueue and not self.facingRight:
				self.facingRight=False
				self.dy=self.dy+9
				self.dx=self.dx+14
				self.x_bound.unbound(self)
			elif DECISIONS.MOVE_DOWN in self.decisionQueue and DECISIONS.JUMP in self.decisionQueue:
				if self.facingRight:
					self.dx=self.dx-2
				else:
					self.dx=self.dx+2
				self.dy=self.dy-12
				self.x_bound.unbound(self)
		elif self.currentState==ON_CEILING_BY_WALL:
			if DECISIONS.MOVE_LEFT in self.decisionQueue and self.facingRight:
				self.dx=self.dx-self.getWalkingSpeed()
			elif self.x_bound.x_cross and DECISIONS.MOVE_LEFT in self.decisionQueue and DECISIONS.JUMP in self.decisionQueue and not self.facingRight:
				self.x_bound.to_x_other_side(self)
			elif DECISIONS.MOVE_RIGHT in self.decisionQueue and not self.facingRight:
				self.dx=self.dx+self.getWalkingSpeed()
			elif self.x_bound.x_cross and DECISIONS.MOVE_RIGHT in self.decisionQueue and DECISIONS.JUMP in self.decisionQueue and self.facingRight:
				self.x_bound.to_x_other_side(self)
			elif DECISIONS.MOVE_DOWN in self.decisionQueue and self.canClimb(self.x_bound):
				self.dy=self.dy-5
		elif self.currentState==ON_CEILING:
			if self.inStateFor==1:
				self.crawl=False
			if DECISIONS.MOVE_LEFT in self.decisionQueue:
				self.facingRight=False
				self.dx=self.dx-self.getWalkingSpeed()
			elif DECISIONS.MOVE_RIGHT in self.decisionQueue:
				self.facingRight=True
				self.dx=self.dx+self.getWalkingSpeed()
			elif DECISIONS.MOVE_UP in self.decisionQueue and -0.25*self.getWidth()<=self.y_bound.rightSide()-self.x<=0.25*self.getWidth() and self.thereIsNothingElse((self.y_bound.rightSide()+2,self.y_bound.lowerSide()+1),None):
				b=self.y_bound
				b.unbound(self)
				self.reposition(b.rightSide()+0.5*self.getWidth(),self.y+0.5*self.getCrawlHeight())
				self.coordDump()
				self.facingRight=False
				b.boundX(self,False)
			elif DECISIONS.MOVE_UP in self.decisionQueue and -0.25*self.getWidth()<=self.y_bound.leftSide()-self.x<=0.25*self.getWidth() and self.thereIsNothingElse((self.y_bound.leftSide()-2,self.y_bound.lowerSide()+1),None):
				b=self.y_bound
				b.unbound(self)
				self.reposition(b.leftSide()-0.5*self.getWidth(),self.y+0.5*self.getCrawlHeight())
				self.coordDump()
				self.facingRight=True
				b.boundX(self,False)
			if DECISIONS.MOVE_DOWN in self.decisionQueue and DECISIONS.JUMP in self.decisionQueue:
				self.dy=self.dy-5
		elif self.currentState==ON_THIN:
			if DECISIONS.MOVE_LEFT in self.decisionQueue:
				self.facingRight=False
				self.dx=self.dx-self.getWalkingSpeed()
			elif DECISIONS.MOVE_RIGHT in self.decisionQueue:
				self.facingRight=True
				self.dx=self.dx+self.getWalkingSpeed()	
			if DECISIONS.MOVE_DOWN in self.decisionQueue and DECISIONS.JUMP in self.decisionQueue:
				self.dy=self.dy-19
			elif DECISIONS.JUMP in self.decisionQueue:
				self.dy=self.dy+19
		elif self.currentState==CRAWL:
			if self.inStateFor==1:
				self.crawl=True
			if DECISIONS.MOVE_LEFT in self.decisionQueue:
				self.facingRight=False
				self.dx=self.dx-self.getCrawlingSpeed()
			elif DECISIONS.MOVE_RIGHT in self.decisionQueue:
				self.facingRight=True
				self.dx=self.dx+self.getCrawlingSpeed()
			if (not DECISIONS.MOVE_DOWN in self.decisionQueue) and self.thereIsNothingElse((self.x-0.5*self.getWidth(),self.y+self.getFullHeight()),None) and self.thereIsNothingElse([self.x+0.5*self.getWidth(),self.y+self.getFullHeight()],None) and self.thereIsNothingElse([self.x,self.y+self.getFullHeight()],self.x_bound):
				self.crawl=False
				self.inStateFor=0
				self.currentState=ON_GROUND
		elif self.currentState==ON_GROUND_WALKING:
			if DECISIONS.MOVE_LEFT in self.decisionQueue:
				self.facingRight=False
				self.dx=self.dx-self.getWalkingSpeed()
			elif DECISIONS.MOVE_RIGHT in self.decisionQueue:
				self.facingRight=True
				self.dx=self.dx+self.getWalkingSpeed()	
			elif not DECISIONS.MOVE_RIGHT in self.decisionQueue and not DECISIONS.MOVE_LEFT in self.decisionQueue:
				self.currentState=ON_GROUND
				self.inStateFor=0
			if not DECISIONS.MOVE_DOWN in self.decisionQueue and DECISIONS.JUMP in self.decisionQueue:
				self.dy=self.dy+19
				self.y_bound.unbound(self)
			elif DECISIONS.MOVE_DOWN in self.decisionQueue:
				self.currentState=CRAWL
				self.inStateFor=0
			elif DECISIONS.RUN in self.decisionQueue:
				self.currentState=ON_GROUND_RUNNING
				self.inStateFor=0	
		elif self.currentState==ON_GROUND:
			if DECISIONS.STANDART_ATTACK in self.decisionQueue:
				print "fire!"
				self.weaponUse()
			elif DECISIONS.MAGICK_ATTACK_START in self.decisionQueue and self.magickEquipped and self.magickEquipped.instant:
				#print "rat!"
				self.magickUse()
			elif (DECISIONS.MAGICK_ATTACK_STOP in self.decisionQueue or not DECISIONS.MAGICK_ATTACK_SUSTAIN in self.decisionQueue) and self.magickEquipped and self.magickEquipped.sustained and self.magickEquipped.active:
				self.magickEquipped.dispel(self)
			if DECISIONS.MOVE_LEFT in self.decisionQueue:
				self.facingRight=False
				self.dx=self.dx-self.getWalkingSpeed()
				self.currentState=ON_GROUND_WALKING
				self.inStateFor=0
			elif DECISIONS.MOVE_RIGHT in self.decisionQueue:
				self.facingRight=True
				self.dx=self.dx+self.getWalkingSpeed()
				self.currentState=ON_GROUND_WALKING
				self.inStateFor=0
			elif not DECISIONS.MOVE_DOWN in self.decisionQueue and DECISIONS.JUMP in self.decisionQueue:
				self.dy=self.dy+19
				self.y_bound.unbound(self)
			elif self.y_bound and self.y_bound.clingable() and DECISIONS.MOVE_DOWN in self.decisionQueue and -0.25*self.getWidth()<=self.y_bound.leftSide()-self.x<=0.25*self.getWidth() and self.thereIsNothingElse((self.y_bound.leftSide()-2,self.y_bound.upperSide()),None):
				b=self.y_bound
				b.unbound(self)
				self.reposition(b.leftSide()-0.5*self.getWidth(),self.y-self.getHeight()+0.5*self.getCrawlHeight())
				self.coordDump()
				self.facingRight=True
				b.boundX(self,True)
			elif self.y_bound and self.y_bound.clingable() and DECISIONS.MOVE_DOWN in self.decisionQueue and -0.25*self.getWidth()<=self.y_bound.rightSide()-self.x<=0.25*self.getWidth() and self.thereIsNothingElse((self.y_bound.rightSide()+2,self.y_bound.upperSide()),None):
				b=self.y_bound
				b.unbound(self)
				self.reposition(b.rightSide()+0.5*self.getWidth(),self.y-self.getHeight()+0.5*self.getCrawlHeight())
				self.coordDump()
				self.facingRight=False
				b.boundX(self,True)
			elif DECISIONS.MOVE_DOWN in self.decisionQueue:
				self.currentState=CRAWL
				self.inStateFor=0
			elif DECISIONS.DRAG_START in self.decisionQueue and not self.dragging and self.startDragging():
				self.currentState=DRAGS
				self.inStateFor=0
		elif self.currentState==ON_GROUND_BY_WALL:
			if self.x_bound.x_cross and DECISIONS.MOVE_LEFT in self.decisionQueue and DECISIONS.JUMP in self.decisionQueue and not self.facingRight:
				self.x_bound.to_x_other_side(self)
			elif DECISIONS.MOVE_LEFT in self.decisionQueue and self.facingRight:
				self.dx=self.dx-75.0/12
			elif self.x_bound.x_cross and DECISIONS.MOVE_RIGHT in self.decisionQueue and DECISIONS.JUMP in self.decisionQueue and self.facingRight:
				self.x_bound.to_x_other_side(self)
			elif DECISIONS.MOVE_RIGHT in self.decisionQueue and not self.facingRight:
				self.dx=self.dx+75.0/12
			if DECISIONS.MOVE_DOWN in self.decisionQueue:
				self.currentState=CRAWL_BY_WALL
				self.inStateFor=0
			elif DECISIONS.MOVE_UP in self.decisionQueue and self.canClimb(self.x_bound):
				self.dy=self.dy+5
				self.y_bound.unbound(self)
		elif self.currentState==CRAWL_BY_WALL:
			if self.inStateFor==1:
				self.crawl=True
			if DECISIONS.MOVE_LEFT in self.decisionQueue and self.facingRight:
				#self.facingRight=False
				self.dx=self.dx-self.getCrawlingSpeed()
			elif DECISIONS.MOVE_RIGHT in self.decisionQueue and not self.facingRight:
				#self.facingRight=True
				self.dx=self.dx+self.getCrawlingSpeed()
			if (not DECISIONS.MOVE_DOWN in self.decisionQueue) and self.thereIsNothingElse([self.x-0.5*self.getWidth(),self.y+self.getFullHeight()],self.x_bound) and self.thereIsNothingElse([self.x+0.5*self.getWidth(),self.y+self.getFullHeight()],self.x_bound) and self.thereIsNothingElse([self.x,self.y+self.getFullHeight()],self.x_bound):
				self.crawl=False
				self.inStateFor=0
				self.currentState=ON_GROUND_BY_WALL
		elif self.currentState==BY_WALL:
			if self.inStateFor==1:
				self.crawl=False
				#self.hangsFromButtom=False
			self.dy=self.dy-self.x_bound.slideDown(self)
			if self.canClimb(self.x_bound):
				if DECISIONS.MOVE_DOWN in self.decisionQueue:
					self.dy=self.dy-5
				elif DECISIONS.MOVE_UP in self.decisionQueue:
					self.dy=self.dy+5
			if DECISIONS.MOVE_LEFT in self.decisionQueue and DECISIONS.JUMP in self.decisionQueue and self.facingRight:
				self.facingRight=False
				self.dy=self.dy+9
				self.dx=self.dx-14
				self.x_bound.unbound(self)
			elif self.x_bound.x_cross and DECISIONS.MOVE_LEFT in self.decisionQueue and DECISIONS.JUMP in self.decisionQueue:
				self.x_bound.to_x_other_side(self)
			elif DECISIONS.MOVE_RIGHT in self.decisionQueue and DECISIONS.JUMP in self.decisionQueue and not self.facingRight:
				self.facingRight=True
				self.dy=self.dy+9
				self.dx=self.dx+14
				self.x_bound.unbound(self)
			elif self.x_bound.x_cross and DECISIONS.MOVE_RIGHT in self.decisionQueue and DECISIONS.JUMP in self.decisionQueue:
				self.x_bound.to_x_other_side(self)
		if self.currentState==FREE_FALL_START and self.inStateFor>=7:
			self.currentState=FREE_FALL
			self.inStateFor=0
		self.inStateFor=self.inStateFor+1
	def __init__(self,x=0,y=0,mass=80):
		Something.Something.__init__(self,x=x,y=y,mass=mass)
		self.decisionQueue=[]
		self.dragging=None
		self.crawl=False
		self.weaponEquipped=None
		self.magickEquipped=None
		self.inStateFor=1
		self.currentState=FREE_FALL_START
		self.transmogrified=None
		self.image1=image1
		self.image3=image3
		self.originalForm=None
		self.stayInThisForm=-1
		self.look=(1,0)
		self.cur_health=100
		self.max_health=100
		self.defense=1
		self.stunned=0
		self.electricResist=0
		self.canCollect=False
		self.inventory=[]
		self.hasGlassClone=None
		self.isGlassCloneOf=None
	def isAlive(self):
		return not self.dead
	def getMass(self):
		return self.ownMass
	def die(self):
		self.dead=True
		self.dragging=None
		self.totalUnbound()
		if self.hasGlassClone:
			self.hasGlassClone.die()
		if self.originalForm:
			self.originalForm.die()
			self.magickEquipped.use()
		if self.isGlassCloneOf:
			self.isGlassCloneOf.hasGlassClone=None
	def getWidth(self):
		if self.y_bound and self.y_bound.isThin():
			return image2.get_width()
		elif self.isAlive() and self.crawl:
			return self.image3.get_width()
		elif self.isAlive():
			return self.image1.get_width()
		return image4.get_width()
	def getHeight(self):
		if self.crawl:
			return self.image3.get_height()
		elif self.dead:
			return image4.get_height()
		return self.image1.get_height()
	def drawingInformation(self):
		if self.dead:
			im=image4 if self.facingRight else pygame.transform.flip(image4,True,False)
		elif self.crawl:
			im=self.image3 if self.facingRight else pygame.transform.flip(self.image3,True,False)
		elif self.y_bound and self.y_bound.isThin():
			im=image2
		else:
			im=self.image1 if self.facingRight else pygame.transform.flip(self.image1,True,False)
		return (self.x-0.5*self.getWidth(),self.y+self.getHeight()),im
	def updateCoords(self):	
		self.prev_x=self.x
		self.prev_y=self.y
		self.x=self.x+self.dx
		self.y=self.y+self.dy
	def solveDecisions(self):
		while DECISIONS.MOVE_LEFT in self.decisionQueue and DECISIONS.MOVE_RIGHT in self.decisionQueue:
			self.decisionQueue.remove(DECISIONS.MOVE_LEFT)
			self.decisionQueue.remove(DECISIONS.MOVE_RIGHT)
		while DECISIONS.MOVE_UP in self.decisionQueue and DECISIONS.MOVE_DOWN in self.decisionQueue:
			self.decisionQueue.remove(DECISIONS.MOVE_UP)
			self.decisionQueue.remove(DECISIONS.MOVE_DOWN)
		self.figureNextState()
	def canClimb(self,it):
		#return True
		if self.dead:
			return False
		return True
	def thereIsNothingElse(self,here,it):
		flag=False
		i=0
		pl_list=self.cur_room.platformList_lu[:]
		while not flag and i < len(pl_list):
			flag=not (pl_list[i] is it) and pl_list[i].pointOfPlatform(here[0],here[1])
			i=i+1
		return not flag
	def checkForCurrentState(self):
		if self.x_bound and self.y_bound and self.hangsFromButtom:
			self.currentState=ON_CEILING_BY_WALL
		elif self.x_bound and self.y_bound and not self.x_cling and  not self.crawl:
			self.currentState=ON_GROUND_BY_WALL
		elif self.x_bound and self.y_bound and not self.x_cling:
			self.currentState=CRAWL_BY_WALL
		elif self.x_bound and self.x_cling:
			self.currentState=CLING_BY_WALL
		elif self.x_bound and self.x_bound.isSlim():
			self.currentState=BY_SLIM
		elif self.x_bound:
			self.currentState=BY_WALL
		elif self.y_bound and self.hangsFromButtom:
			self.currentState=ON_CEILING
		elif self.y_bound and self.crawl:
			self.currentState=CRAWL
		elif self.y_bound and self.y_bound.isThin():
			self.currentState=ON_THIN
		elif self.y_bound and self.dragging:
			self.currentState=DRAGS
		elif self.y_bound:
			self.currentState=ON_GROUND
		elif not self.x_bound and not self.y_bound:
			self.currentState=FREE_FALL_START
		self.inStateFor=0
	def getWalkingSpeed(self):
		return 75.0/12
	def getFullHeight(self):
		return self.image1.get_height()
	def getCrawlingSpeed(self):
		return self.getWalkingSpeed()*2.0/3
	def getCrawlHeight(self):
		return self.image3.get_height()
	def changeHPby(self,amount):
		self.cur_health=self.cur_health-amount
		if self.cur_health>self.max_health:
			self.cur_health=self.max_health
	def neurotoxicDamageTaken(self,amount):
		self.putInStun(amount)
	def physicalDamageTaken(self,amount):
		import random
		if int(amount)>=self.defense:
			m=self.defense
		else:
			m=int(amount)
		a=int(amount)-random.randint(0,m)
		self.changeHPby(a)
		return a
	def electricDamageTaken(self,amount):
		a=amount*(1-self.electricResist)
		self.changeHPby(a)
		return a
	def weaponUse(self):
		if self.weaponEquipped:
			self.weaponEquipped.attack(self)
	def startDragging(self):
		print "drag+"
		#l=self.y_bound.boundedList
		l=self.cur_room.containers
		f=None
		i=0
		while not f and i<len(l):
			li=l[i]
			if (li is not self) and (li.y==self.y) and (-0.5*(self.getWidth()+li.getWidth())<li.x-self.x<0.5*(self.getWidth()+li.getWidth())):
				f=li
			i=i+1
		if not (f is None):
			self.dragging=f
			if self.x<f.x:
				self.facingRight=True
				self.x=f.x-0.5*(self.getWidth()+f.getWidth())
			else:
				self.facingRight=False 
				self.x=f.x+0.5*(self.getWidth()+f.getWidth())
			return True
		return False
	def getAgility(self):
		return 7
	def magickUse(self):
		if self.magickEquipped:
			print "it's defenetly a rat"
			self.magickEquipped.use(self)
	def acceptDecision(self,decision):
		char=self.getActingSelf()
		if char.stunned==0:
			char.decisionQueue.append(decision)
	def getActingSelf(self):
		if self.transmogrified:
			return self.transmogrified.getActingSelf()
		elif self.hasGlassClone:
			return self.hasGlassClone.getActingSelf()
		return self
	def giveHimMyDimensional(self,other):
		other.x=self.x
		other.y=self.y
		other.prev_x=self.prev_x
		other.prev_y=self.prev_y
		other.facingRight=self.facingRight
	def transmogrify(self,other,period=-1):
		self.transmogrified=other
		self.giveHimMyDimensional(other)
		other.stayInThisForm=period
		other.originalForm=self
		self.cur_room.addAnotherCharacter(other)
		self.cur_room.protagonists.remove(self)
		self.cur_room=None
	def transmogrifyBack(self):
		orf=self.originalForm
		self.giveHimMyDimensional(orf)
		self.cur_room.addAnotherCharacter(orf)
		self.cur_room.protagonists.remove(self)
		self.cur_room=None
		orf.transmogrified=None
	def setLook(self,newlook):
		self.getActingSelf().look=newlook
	def getRunningSpeed(self):
		return 3*self.getWalkingSpeed()
	def getScudSpeed(self):
		return 4*self.getWalkingSpeed()
	def putInStun(self,time):
		self.stunned=self.stunned+time
	def deathConfirmation(self):
		import BodyPart
		self.cur_room.protagonists.remove(self)
		if not (self.originalForm or self.isGlassCloneOf):
			dx=self.prev_x-self.x
			dy=self.prev_y-self.y
			bi1=pygame.image.load("head.jpg")
			bi1.set_colorkey((137,44,75))
			bp1=BodyPart.BodyPart(self.x,self.y+self.getHeight()-bi1.get_height(),30,[(-11,-6)],bi1)
			bi2=pygame.image.load("torso.jpg")
			bi2.set_colorkey((137,44,75))
			bp2=BodyPart.BodyPart(self.x,self.y+self.getHeight()-bi1.get_height()-bi2.get_height(),30,[(-12,46),(-10,-34),(-13,40)],bi2)
			bi3=pygame.image.load("foot.jpg")
			bi3.set_colorkey((137,44,75))
			bp3=BodyPart.BodyPart(self.x,self.y,20,[(-13,6)],bi3)
			bp1.prev_x=bp1.x+dx
			bp1.prev_y=bp1.y+dy
			bp2.prev_x=bp2.x+dx
			bp2.prev_y=bp2.y+dy
			bp3.prev_x=bp3.x+dx
			bp3.prev_y=bp3.y+dy
			#link1=RagdollCorpse.BodyLink(bp1,0,bp2,0,14.866)
			#link2=RagdollCorpse.BodyLink(bp2,1,bp3,0,51)
			#corpse=RagdollCorpse.RagdollCorpse([link1,link2])
			#corpse.original=self
			#self.cur_room.corpsesList.append(corpse)
			self.cur_room.junkList.append(bp3)
			self.cur_room.junkList.append(bp2)
			self.cur_room.junkList.append(bp1)
	def postcondition(self):
		if self.originalForm and self.stayInThisForm>0:
			self.stayInThisForm=self.stayInThisForm-1
		elif self.originalForm and self.stayInThisForm==0:
			self.transmogrifyBack()
	def canBeTransformed(self):
		return not self.dead and self.stayInThisForm==-1
	def getIntendedFraction(self):
		if self.originalForm:
			return self.originalForm.fraction
		return self.fraction